package appapi.controller.oider;

import appapi.common.ResponseBean;
import appapi.entity.mqtt.Reserve;
import appapi.service.ReserveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version: java version 1.8
 * @Author: Ygp Work
 * @description:
 * @date: 2023-07-06 13:56
 */
@Api(tags = "保护区接口")
@RestController
@RequestMapping("/api/reserves")
@CrossOrigin
public class ReserveController {
    @Autowired
    private ReserveService reserveService;

    @GetMapping("/devicesId")
    @CrossOrigin
    @ApiOperation(value = "查询保护区信息接口")
    public ResponseBean getAllReserves( Long devicesId) {
        Reserve allReserves = reserveService.getAllReserves(devicesId);
        if (allReserves != null) {
            return ResponseBean.success(allReserves);
        } else {
            return ResponseBean.fail("查询失败，找不到指定的设备");
        }
    }

    @PostMapping("/{devicesId}")
    @CrossOrigin
    @ApiOperation(value = "新增保护区接口")
    public ResponseBean addReserve(@RequestBody Reserve reserve) {
        reserveService.addReserve(reserve);
        return ResponseBean.success();
    }
}